(function(){"use strict";BX.namespace("BX.Main");BX.Main.TileGrid=function(t){BX.TileGrid.Grid.apply(this,arguments);this.navigation=t.navigation;this.isLoadingNextPortion=false;this.init(t);BX.onCustomEvent(window,"BX.TileGrid.Grid:initialized",[this])};BX.Main.TileGrid.prototype={__proto__:BX.TileGrid.Grid.prototype,constructor:BX.Main.TileGrid,bindEvents:function(){BX.TileGrid.Grid.prototype.bindEvents.call(this);window.addEventListener("scroll",BX.throttle(this.handleScroll.bind(this),100))},init:function(t){this.userOptions=new BX.Main.TileGrid.UserOptions(this,t.userOptions,t.userOptionsActions,t.userOptionsHandlerUrl)},handleScroll:function(){if(this.needToShowNextPortion()){this.showNextPortion()}},handleBackspace:function(){window.history.back()},reload:function(t,i){if(!BX.type.isString(t)){t=document.location.toString()}i=i||{};if(BX.message.SITE_ID){i.SITE_ID=BX.message.SITE_ID}i.sessid=BX.bitrix_sessid();var n={gridId:this.getId(),url:t,data:i};BX.onCustomEvent(window,"BX.TileGrid.Grid:beforeReload",[this,n]);t=n.url;i=n.data;var e=BX.ajax.promise({url:BX.util.add_url_param(t,{grid_id:this.getId(),internal:true}),data:i,method:"POST",dataType:"json"});this.setHeightContainer();this.setFadeContainer();if(!this.loader)this.getLoader();this.showLoader();e.then(function(t){this.navigation=t.data.navigation;this.redraw(t.data.tileGrid.items);this.loader.destroy();this.unSetFadeContainer();this.unSetHeightContainer()}.bind(this));return e},getUserOptions:function(){return this.userOptions},prepareSortUrl:function(t){var i=window.location.toString();if("sort_by"in t){i=BX.util.add_url_param(i,{by:t.sort_by})}if("sort_order"in t){i=BX.util.add_url_param(i,{order:t.sort_order})}return i},sortByColumn:function(t){var i=t;i.sort_url=this.prepareSortUrl(t);this.getUserOptions().setSort(i.sort_by,i.sort_order,function(){this.reload(i.sort_url,{grid_action:"sort"})}.bind(this))},needToShowNextPortion:function(){if(!this.navigation.hasNextPage){return false}var t=BX.pos(this.container).height;var i=document.body.offsetHeight;var n=t-i+this.container.getBoundingClientRect().top;var e=parseInt(this.navigation.pageSize/this.countItemsPerRow,10);var r=BX.pos(this.items[0].layout.container).height;if(r*Math.max(1,parseInt(e*.5,10))>=n){return true}return false},showNextPortion:function(){if(!this.navigation.hasNextPage||this.isLoadingNextPortion){return}this.isLoadingNextPortion=true;var t=BX.ajax.promise({url:BX.util.add_url_param(this.navigation.urlNextPage,{grid_id:this.getId(),internal:true}),method:"POST",dataType:"json"});t.then(function(t){this.isLoadingNextPortion=false;t.data.tileGrid.items.forEach(function(i){this.appendItem(i);this.navigation=t.data.navigation},this)}.bind(this)).catch(function(){this.isLoadingNextPortion=false}.bind(this))}}})();
//# sourceMappingURL=script.map.js